package com.practices2.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.practices2.R;
import com.practices2.testdata.StringUrls;
import com.practices2.util.Util;
import com.practices2.util.http.AsyncHttpClient;
import com.practices2.util.http.AsyncHttpResponseHandler;

public class MainActivity extends Activity {

	private Intent mIntent;
	// 定义控件
	private TextView tv_content;
	private Button btn_ImageList, btn_Download;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
	}

	private void initView() {

		tv_content = (TextView) findViewById(R.id.tv_content);
		btn_ImageList = (Button) findViewById(R.id.btn_ImageListAcitivity);
		btn_ImageList.setOnClickListener(btnOnClickListener);

		btn_Download = (Button) findViewById(R.id.btn_DownloadActivity);
		btn_Download.setOnClickListener(btnOnClickListener);
		//
		// AsyncHttpClient httpClient = new AsyncHttpClient();
		// httpClient.get(StringUrls.stringUrls[0], httpResponseHandler);

	}

	private OnClickListener btnOnClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btn_ImageListAcitivity:
				Intent intent = new Intent();
				mIntent.setClass(MainActivity.this, ImageListAcitvity.class);
				startActivity(mIntent);
				break;
			case R.id.btn_DownloadActivity:
				Intent mIntent = new Intent();
				mIntent.setClass(MainActivity.this, DownloadAcitivity.class);
				startActivity(mIntent);
				break;
			default:
				break;
			}
		}
	};

	private AsyncHttpResponseHandler httpResponseHandler = new AsyncHttpResponseHandler() {

		@Override
		public void onStart() {
			super.onStart();
			Util.showProgressDialogWithText(MainActivity.this, "Loading...");
		}

		@Override
		public void onFinish() {
			super.onFinish();
			Util.dismissProgressDialog();
		}

		@Override
		public void onSuccess(String content) {
			super.onSuccess(content);
			tv_content.setText(content);
		}

		@Override
		public void onFailure(Throwable error, String content) {
			super.onFailure(error, content);

		}
	};

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
